package com.ocean.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ocean.admin.core.annotation.Log;
import com.ocean.admin.core.annotation.enums.BusinessType;
import com.ocean.admin.model.dto.dicdata.SysDictDataQueryDTO;
import com.ocean.admin.model.dto.dicdata.SysDictDataSaveDTO;
import com.ocean.admin.model.dto.dicdata.SysDictDataUpdateDTO;
import com.ocean.admin.model.vo.dicdata.SysDictDataVo;
import com.ocean.admin.service.ISysDictDataService;
import com.ocean.core.util.response.ResultSet;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 字典数据表 前端控制器
 * </p>
 *
 * @author zhang
 * @since 2022-08-16
 */
@Tag(name = "字典数据")
@RestController
@RequestMapping("/admin/sys-dict-data")
public class SysDictDataController {

    @Autowired
    private ISysDictDataService iSysDictDataService;

    /**
     * 分页查询字典数据
     *
     * @param queryDTO 查询条件
     * @return 结果
     */
    @Operation(summary = "分页查询字典数据")
    @PreAuthorize("@ss.hasPermission('system:dict:pageList')")
    @PostMapping("/pageList")
    public ResultSet<IPage<SysDictDataVo>> pageList(@Validated @RequestBody SysDictDataQueryDTO queryDTO) {
        return ResultSet.ok(iSysDictDataService.pageList(queryDTO));
    }

    /**
     * 新增字典类型
     *
     * @param saveDTO 字典信息
     * @return 结果
     */
    @Operation(summary = "新增字典类型")
    @PreAuthorize("@ss.hasPermission('system:dict:saveDic')")
    @Log(title = "字典数据管理", businessType = BusinessType.INSERT)
    @PostMapping(value = "saveDicData")
    public ResultSet<String> saveDicData(@Validated @RequestBody SysDictDataSaveDTO saveDTO) {
        return ResultSet.ok(iSysDictDataService.saveDicData(saveDTO));
    }

    /**
     * 修改字典类型
     *
     * @param updateDTO 字典信息
     * @return 结果
     */
    @Operation(summary = "修改字典类型")
    @PreAuthorize("@ss.hasPermission('system:dict:updateDic')")
    @Log(title = "字典数据管理", businessType = BusinessType.UPDATE)
    @PostMapping(value = "updateDicData")
    public ResultSet<String> updateDicData(@Validated @RequestBody SysDictDataUpdateDTO updateDTO) {
        return ResultSet.ok(iSysDictDataService.updateDicData(updateDTO));
    }

    /**
     * 删除字典类型
     *
     * @param dataId 字典编码
     * @return 结果
     */
    @Operation(summary = "删除字典类型")
    @PreAuthorize("@ss.hasPermission('system:dict:removeDic')")
    @Log(title = "字典类型管理", businessType = BusinessType.DELETE)
    @GetMapping("removeDicData/{dataId}")
    public ResultSet<String> removeDicData(@PathVariable Long[] dataId) {
        return ResultSet.ok(iSysDictDataService.removeDicData(dataId));
    }
}
